﻿using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using FacialClub.Models.Entities;
using FacialClub.Models.Interfaces;
namespace FacialClub.Models.Repositories
{
    /// <summary>
    /// Subscription Repository
    /// </summary>
    public class SubscriptionRepository : ISubscriptionRepository
    {
        readonly FacialClubEntities _db = new FacialClubEntities();

        /// <summary>
        /// Get Notification Details by Template Name
        /// </summary>
        /// <param name="strQuery"></param>
        /// <returns></returns>
        public IQueryable<Subscription> FindSubscriptionByName(string strQuery)
        {
            return _db.Subscriptions.Where(d => d.FirstName.Contains(strQuery));
        }

        /// <summary>
        /// Get All Subscription
        /// </summary>
        /// <returns></returns>
        public IQueryable<Subscription> FindAllSubscription()
        {
            return _db.Subscriptions;
        }

        /// <summary>
        /// Get Subscription by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Subscription GetSubscriptionById(int id)
        {
            return _db.Subscriptions.SingleOrDefault(d => d.SubscriptionId == id);
        }

        /// <summary>
        /// Add Subscription in the Database
        /// </summary>
        /// <param name="subscription"></param>
        public void Add(Subscription subscription)
        {
            _db.Subscriptions.AddObject(subscription);
        }

        /// <summary>
        /// Delete Subscription from Database
        /// </summary>
        /// <param name="subscription"></param>
        public void Delete(Subscription subscription)
        {
            _db.Subscriptions.DeleteObject(subscription);
        }

        /// <summary>
        /// Save Subscription in the database
        /// </summary>
        public void Save()
        {
            _db.SaveChanges();
        }

        /// <summary>
        /// Get Country States
        /// </summary>
        /// <returns></returns>
        public List<CountryStates> GetCountryStates()
        {
            return _db.CountryStates.ToList();
        }
    }
}